package alg20241021;

public class Text {
    public static void main(String[] args) {
        int[] nums = {1,4,4};
        System.out.println(minSubArrayLen(4, nums));
    }
    public static int minSubArrayLen(int target, int[] nums) {
        int sum = 0, len = Integer.MAX_VALUE;
        int n = nums.length;
        for (int left = 0, right = 0; right < n; right++) {
            sum += nums[right];
            while(sum >= target){
                len = Math.min(len, right-left+1);
                sum -= nums[left++];
            }
        }
        return len == Integer.MAX_VALUE ? 0 : len;
    }
}
